using System;
using System.Windows.Forms;
using HgAdapter;
using HogoLogic;
using ProjectView;

namespace HogoWinClient
{
	public partial class MainForm : Form
	{
		private static readonly string projectsStorageFilename = "projects";
		private static HogoProjectList projects = new HogoProjectList();
		TipsForm tipsForm = new TipsForm();


		public MainForm()
		{
			InitializeComponent();
		}

		private void exitItem_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void SaveAppearenceState()
		{
			AppearenceSettings.Default.MainFormWindowState = this.WindowState;
			AppearenceSettings.Default.Save();
		}

		private void LoadAppearenceState()
		{
			this.WindowState = AppearenceSettings.Default.MainFormWindowState;
		}

		private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			SaveAppearenceState();
			projects.SaveToFile(projectsStorageFilename);
		}

		private void logItem_Click(object sender, EventArgs e)
		{
			string output = (new HgLog().Run());
		}

		private void MainForm_Shown(object sender, EventArgs e)
		{
			tipsForm.ShowDialog();
			HogoProject chosenProject = ChooseProject();
			hogoFileSystemView.Open(chosenProject.ProjectFolder);
		}

		private HogoProject ChooseProject()
		{
			projects.LoadFromFile(projectsStorageFilename);

			return projectView.SelectProject(projects);
		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			LoadAppearenceState();
		}

		private void tipsToolStripMenuItem_Click(object sender, EventArgs e)
		{
			tipsForm.ShowDialog();
		}
	}
}